var geocoder;
var address
$(function() {
	if ($("#request").val() == "1") {
		apprise("Adding place was not success")
	}
	if ($("#request").val() == "2") {
		apprise("Adding place was success,but you should add some information")
	}
	if ($("#request").val() == "3") {
		apprise("Adding place was success")
	}
	$("#request").val("")

	$("#app-bt-next1").click(function() {
			if (($("#address").val() == "")|| ($("#cbbcity").val() == "---Choose One---")) {
				apprise("Address,City is not null, please type it if you want to add place!!!!!!!!");
			} else {
				if(($("#cbbdt").val()=="---Choose One---")||($("#tfprice").val()=="")||($("#cbbbr").val()=="---Choose One---")){
					apprise("Information about your place is not full, you should fill all infor about your place!!!!!!!!!")
				}
				$("#app-bt-tab1-o").show();
				$("#app-bt-tab2-c").show();
				$("#app-bt-tab2-o").hide();
				$("#app-bt-tab1-c").hide();
				$("#app-bt-tab3-o").show();
				$("#app-bt-tab3-c").hide();
				$("#app-taber2").show();
				$("#app-taber1").hide();
				$("#app-taber3").hide();
				geocoder = new google.maps.Geocoder();
				address = $("#address").val() + " da nang";
				// apprise(address);
				geocoder.geocode(
					{
						'address' : address
					},
					function(results, status) {
						if (status == google.maps.GeocoderStatus.OK) {
							$("#tf-lat").val(results[0].geometry.location.lat());
							$("#tf-lng").val(results[0].geometry.location.lng());
							}
						});
				}
			});

	$("#app-bt-back2").click(function() {
		$("#app-bt-tab1-c").show();
		$("#app-bt-tab2-o").show();
		$("#app-bt-tab2-c").hide();
		$("#app-bt-tab1-o").hide();
		$("#app-bt-tab3-o").show();
		$("#app-bt-tab3-c").hide();
		$("#app-taber2").hide();
		$("#app-taber1").show();
		$("#app-taber3").hide();
	})
	$("#app-bt-next2").click(function() {
		$("#app-bt-tab1-o").show();
		$("#app-bt-tab2-o").show();
		$("#app-bt-tab2-c").hide();
		$("#app-bt-tab1-c").hide();
		$("#app-bt-tab3-c").show();
		$("#app-bt-tab3-o").hide();
		$("#app-taber2").hide();
		$("#app-taber1").hide();
		$("#app-taber3").show();
	})
	$("#app-bt-back3").click(function() {
		$("#app-bt-tab1-o").show();
		$("#app-bt-tab2-c").show();
		$("#app-bt-tab2-o").hide();
		$("#app-bt-tab1-c").hide();
		$("#app-bt-tab3-o").show();
		$("#app-bt-tab3-c").hide();
		$("#app-taber2").show();
		$("#app-taber1").hide();
		$("#app-taber3").hide();
	})
	$("#btfinish").click(function(){
		$("#div-alert").show();
	})
	$("#btno").click(function(){
		$("#div-apprise").hide();
		$("#app-bt-tab1-c").show();
		$("#app-bt-tab2-o").show();
		$("#app-bt-tab2-c").hide();
		$("#app-bt-tab1-o").hide();
		$("#app-bt-tab3-o").show();
		$("#app-bt-tab3-c").hide();
		$("#app-taber2").hide();
		$("#app-taber1").show();
		$("#app-taber3").hide();
	})
	

	// $("#bt-finish").click(function(){
	// var address = "Sydney, NSW";
	//
	// geocoder.geocode( { 'address': address}, function(results, status) {
	// if (status == google.maps.GeocoderStatus.OK) {
	// var latitude = results[0].geometry.location.lat();
	// var longitude = results[0].geometry.location.lng();
	// apprise(latitude);
	// apprise(longitude);
	//	            
	// } else {
	// apprise('Geocode was not successful for the following reason: ' + status);
	// }
	// });
	// });
})

function getcity() {

	$(".option").each(function() {

		$(this).remove();

	});
	var idcity = $("#cbbcity").val();

	$.ajax({
		url : "loaddistrict",
		type : "GET",
		data : {
			idcity : idcity
		},
		contentType : "application/json; charset=utf-8",
		dataType : 'json',
		success : function(data) {
			$.each(data, function(i, value) {
				// console.log(value.districtName);
				// console.log(value.id);
				$('#cbbdt').append(
						$('<option>').text(value.districtName).attr('class',
								'option'));
			});
		}
	})

}